package net.zjitc.service.impl;

import net.zjitc.dao.CategoryDao;
import net.zjitc.dao.CategorySecondDao;
import net.zjitc.dao.impl.CategoryDaoImpl;
import net.zjitc.dao.impl.CategorySecondDaoImpl;
import net.zjitc.pojo.Category;
import net.zjitc.pojo.CategorySecond;
import net.zjitc.service.CategoryService;

import java.util.List;

/**
 * Created by rj1502 on 2017/11/14.
 */
public class CategoryServiceImpl implements CategoryService {
    CategoryDao dao = new CategoryDaoImpl();
    CategorySecondDao csdao = new CategorySecondDaoImpl();
    //查询所有的一级分类
    public List<Category> findAll() {
        List<Category> list = dao.findAll();
        //通过每个一级分类查出相关的所有的二级分类，并设置为一级分类的成员，为页面显示准备
        for(Category c:list){
            List<CategorySecond> cslist = csdao.findByCid(c.getCid());
            c.setCategorySecondList(cslist);
        }
        return list;
    }

    public int insert(Category category) {
        return dao.insert(category);
    }

    public int delete(String cid) {
        return dao.delete(cid);
    }

    public int update(Category category) {
        return dao.update(category);
    }

    public Category findByCid(String cid) {
        return dao.findByCid(cid);
    }
}
